package us.wili.dev.client.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import us.wili.dev.client.model.req.AddOrderReq;
import us.wili.dev.client.model.req.OrderReq;
import us.wili.dev.client.model.rsp.OrderDetaRsp;
import us.wili.dev.client.model.rsp.OrderRsp;
import us.wili.dev.client.model.rsp.ShopcartRsp;
import us.wili.dev.client.service.ClientOrderService;
import us.wili.dev.common.model.ResponseDto;
import us.wili.dev.common.util.ResponseUtil;
import us.wili.dev.model.entity.Order;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

@Validated
@RestController
@RequestMapping("/api/order")
@Api(tags = "订单")
public class OrderController {
    @Autowired
    private ClientOrderService clientOrderService;

    @ApiOperation(value = "储存订单信息",nickname = "insertOrder")
    @RequestMapping(value = "/insertOrder",method = RequestMethod.POST)
    public ResponseDto<OrderRsp> insertOrder(@Valid @RequestBody AddOrderReq req,HttpServletRequest request,HttpServletResponse response){
        Order order = clientOrderService.insertorder(req);
        return ResponseUtil.getSuccessRsp(order);
    }

    @ApiOperation(value = "删除订单", nickname = "deleteorder")
    @RequestMapping(value = "/deleteorder", method = RequestMethod.GET)
    public ResponseDto deleteorder(Long id) {
        clientOrderService.deleteorder(id);
        return new ResponseDto();
    }

    @ApiOperation(value = "我的订单", nickname = "myorder")
    @RequestMapping(value = "/myorder", method = RequestMethod.GET)
    public ResponseDto<OrderRsp> myorder(OrderReq req){
        List<OrderRsp> rsp =clientOrderService.myorder(req);
        return ResponseUtil.getSuccessRsp(rsp);
    }

    @ApiOperation(value = "待付款", nickname = "WaitingForTheBuy")
    @RequestMapping(value = "/WaitingForTheBuy", method = RequestMethod.GET)
    public ResponseDto<ShopcartRsp> WaitingForTheBuy(Long id){
        List<ShopcartRsp> rsp =clientOrderService.WaitingForTheBuy(id);
        return ResponseUtil.getSuccessRsp(rsp);
    }

    @ApiOperation(value = "待付款详情", nickname = "WaitingForTheBuydeta")
    @RequestMapping(value = "/WaitingForTheBuydeta", method = RequestMethod.GET)
    public ResponseDto<ShopcartRsp> WaitingForTheBuydeta(Long id){
        OrderDetaRsp rsp =clientOrderService.WaitingForTheBuydeta(id);
        return ResponseUtil.getSuccessRsp(rsp);
    }

    @ApiOperation(value = "待收货", nickname = "WaitingForTheclosed")
    @RequestMapping(value = "/WaitingForTheclosed", method = RequestMethod.GET)
    public ResponseDto<ShopcartRsp> WaitingForTheclosed(Long id){
        List<ShopcartRsp> rsp =clientOrderService.WaitingForTheclosed(id);
        return ResponseUtil.getSuccessRsp(rsp);
    }

    @ApiOperation(value = "待发货", nickname = "WaitingForThedelivery")
    @RequestMapping(value = "/WaitingForThedelivery", method = RequestMethod.GET)
    public ResponseDto<ShopcartRsp> WaitingForThedelivery(Long id){
        List<ShopcartRsp> rsp =clientOrderService.WaitingForThedelivery(id);
        return ResponseUtil.getSuccessRsp(rsp);
    }
}
